package zj.com.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.Serializable;
import java.util.List;

import zj.com.activities.DzgDetailEditActivity;
import zj.com.activities.LookImgActivity;
import zj.com.model.DjcModel;
import zj.com.model.DzgInspectTask;
import zj.com.zj.R;

/**
 * Created by xi on 16/6/3.
 */
public class DzgDetailAdapter extends BaseAdapter{

    public List<DzgInspectTask> list;
    public Context context;
    public LayoutInflater inflater;

    public DzgDetailAdapter(List<DzgInspectTask> list, Context context){

        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = new ViewHolder();
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_dzg_detail_item, null);
            viewHolder.lookimg_tv = (TextView) convertView.findViewById(R.id.lookimg_tv);
            viewHolder.update_tv = (TextView) convertView.findViewById(R.id.update_tv);

            viewHolder.name_tv = (TextView) convertView.findViewById(R.id.name_value_tv);
            viewHolder.desc_tv = (TextView) convertView.findViewById(R.id.des_value_tv);
            viewHolder.fen_tv = (TextView) convertView.findViewById(R.id.fen_value_tv);
            viewHolder.risk_value_tv = (TextView) convertView.findViewById(R.id.risk_value_tv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


       final DzgInspectTask task = list.get(position);
        viewHolder.name_tv.setText(task.getInspectContentDesc());
        viewHolder.desc_tv.setText(task.getInspectRiskDesc());
        viewHolder.fen_tv.setText(task.getPoints()+"");
        viewHolder.risk_value_tv.setText(task.getRiskTypeName());
        viewHolder.update_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(context, DzgDetailEditActivity.class);
                intent.putExtra("task",task);
                context.startActivity(intent);
            }
        });

        viewHolder.lookimg_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =     new Intent(context, LookImgActivity.class);
                intent.putExtra("imgs",(Serializable)task.getImgList());
                intent.putExtra("position",0);
                context.startActivity(intent);
            }
        });
        return convertView;
    }
    private static class ViewHolder {
        TextView lookimg_tv;
        TextView update_tv;
        TextView name_tv,desc_tv,fen_tv,risk_value_tv;

    }

    public void setDataChange(List<DzgInspectTask> list){

        this.list = list;
        notifyDataSetChanged();
    }
}
